package com.kt.controller;

import com.kt.domain.User;
import com.kt.service.UserService;
import com.kt.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

// servlet-api
@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {
    UserService userService = new UserServiceImp();
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        String userName = req.getParameter("username");
        String password = req.getParameter("password");
        User user = userService.findByUsername(userName);
        if(user != null) {
            if (password.equals(user.getPassword())){
                res.getWriter().write("ok");
                return;
            }
        }
        res.getWriter().write("error");

    }
}
